

package cn.shengchao.examstar.pay.acl.ports.repositories;

import cn.hutool.core.date.DateTime;
import cn.shengchao.examstar.pay.infrastructure.dao.po.PayOrder;
import cn.shengchao.examstar.pay.infrastructure.dao.po.PayOrderItem;
import cn.shengchao.examstar.rpc.orders.req.*;
import cn.shengchao.examstar.pay.model.aggregate.CreateOrderAggregate;
import cn.shengchao.examstar.pay.model.entity.OrderEntity;
import cn.shengchao.examstar.pay.model.entity.PayOrderEntity;
import cn.shengchao.examstar.pay.model.entity.ShopCartEntity;
import cn.shengchao.examstar.rpc.orders.res.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface IOrderRepository {
    /**
     * 用户统计
     *
     * @param userId 用户
     * @return 订单
     */
    OrderCountInfo countUserPay(Long userId);
    /**
     * 查询未支付订单
     *
     * @param shopCartEntity 购物车实体对象
     * @return 订单实体对象
     */
    OrderEntity queryUnPayOrder(ShopCartEntity shopCartEntity);

    PayOrder queryOrderInfoById(Long orderId);
    List<PayOrderItem> queryOrderItemInfosById(Long orderId);
    /**
     * 保存订单对象
     *
     * @param orderAggregate 订单聚合
     */
    void doSaveOrder(CreateOrderAggregate orderAggregate);

    /**
     * 更新订单支付信息
     *
     * @param payOrderEntity 支付单
     */
    void updateOrderPayInfo(PayOrderEntity payOrderEntity);

    /**
     * 订单支付成功
     *
     * @param orderId 订单ID
     */
    void changeOrderPaySuccess(String orderId);

    List<PayOrder> queryNoPayNotifyOrder();

    List<String> queryTimeoutCloseOrderList();

    boolean changeOrderClose(String orderId);

    List<OrderList> getOrderList(OrderQueryPage orderQueryPage);
    List<OrderList> getOrderImgList(List<Long> orderIds);
    List<OrderItemInfo> queryOrderItemList(String orderId);

    List<OrderChangeLog> queryOrderChangeLogs(String orderId);

    void saveOrderRemarks(Long orderId, String remarks, Long userId);

    List<Remarks> getOrderRemarks(String orderId);

    OrderEntity queryOrder(String orderId);

    BigDecimal getOrderRefundsSum(String orderId);

    //退费
    void refunds(Long operate,
                 String orderId,
                 Long orderItemId,
                 BigDecimal refundPrice,
                 String refundType,
                 String remarks,
                 boolean isAll) throws Exception;

    /**
     * 退费列表
     */
    List<RefundList> getOrderRefund(RefundQueryPage refundQueryPage);

    /**
     * 获取订单金额
     *
     * @param userId    用户id
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return 金额
     */
    Optional<BigDecimal> getOrderAmount(Long userId, DateTime startTime, Date endTime);

    /**
     * 获取订单金额
     *
     * @param userId 用户id
     * @return 金额
     */
    Optional<BigDecimal> getOrderAmount(Long userId);

    List<OrderWithSupplierView> selectOrderViewListByPageQuery(OrderWithSupplierPageQuery orderWithSupplierPageQuery);
    Integer countOrderByOrderId(String orderId);
    BigDecimal countOrderViewAmountByPageQuery(OrderWithSupplierPageQuery orderWithSupplierPageQuery);

    List<SubOrderWithSupplierView> selectSubOrderViewListByPageQuery(SubOrderWithSupplierPageQuery subOrderWithSupplierPageQuery);

    Map<String,BigDecimal> countSubOrderViewAmountByPageQuery(SubOrderWithSupplierPageQuery subOrderWithSupplierPageQuery);

    List<SubOrderWithSupplierView> selectSubOrderListByOrderId(Long orderId);

    List<SubOrderWithSupplierView> selectSubOrderListFromMainOrder(SubOrderForMainPageQuery subOrderForMainPageQuery);
}
